#include "web/UdpSocket.h"
#include "web/Buffer.h"
#include "web/wsa.h"


int main()
{
    WSA::Init();

    auto udpServer = std::make_shared<Web::UdpSocket>();
    Web::SockAddrIn sockAddr;
    sockAddr.SetFamilyAddrPort(AF_INET, INADDR_ANY, 6655);

    if (udpServer->Bind(sockAddr) < 0)
    {
        std::cout << "Bind failed" << std::endl;
        return 0;
    }

    std::cout << " UDP server is listening on port 6655...\n";
    while (1)
    {
        Web::SockAddrIn recvAddr;

        Web::Buffer buf;
        int recvLen = udpServer->RecvFrom<Web::Buffer>(buf, recvAddr);
        printf("%s %d Recv len %d: %d \n", recvAddr.GetIP(), recvAddr.GetPort(), recvLen, buf.no);
    }

    WSA::Clean();
    return 0;
}